import * as actionTypes from './constants';

import list from '../../../common/data';
function reducer(state = list, action) {
  switch (action.type) {
    case actionTypes.CHANGE_DELETE_TODOLIST:
      return [...action.todolist];
    case actionTypes.CHANGE_IS_COMPLETE_TODOLIST:
      return [...action.todolist];
    case actionTypes.CHANGE_Edit_TODOLIST:
      return [...action.todolist];
    case actionTypes.CHANGE_ADD_TODOLIST:
      return [action.todolist, ...state];
    case actionTypes.CHANGE_SEASRCH_TODOLIST:
      if (action.code === '') {
        return list;
      } else {
        return state.filter((item) => {
          return item.content.indexOf(action.code) !== -1;
        });
      }
    default:
      return state;
  }
}

export default reducer;
